package activitytest.example.com.application.utils;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;



/**
 * Created by zhanyihong on 2017/12/7.
 */

public abstract class BaseSetActivity extends Activity{

    private GestureDetector gestureDetector;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //监听手势移动
//下一页
//上一页
        gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                //监听手势移动
                if (e1.getX() - e2.getX() > 0) {
                    //下一页
                   ShowNextPage();
                }
                if (e1.getX() - e2.getX() < 0) {
                    //上一页
                    ShowPrePage();
                }
                return super.onFling(e1, e2, velocityX, velocityY);
            }
        });
    }

    protected abstract void ShowPrePage();

    protected abstract void ShowNextPage();

    public  void  nextPage(View view){
        ShowNextPage();
    }
    public  void  prePage(View view){
        ShowPrePage();
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }
}
